1. Field of the Invention
The present invention relates to the technology of optimizing a program, and more specifically to the technology of merging and deleting an unused data item in the program.
2. Description of the Related Art
Data items such as a variable, etc. are defined in a program in many cases. However, not all defined data items are not used in the program. In the following explanation, a data item defined but used in a program is referred to as an unused data item. Although a data item dictionary is generated during compilation, program analysis, etc., a larger memory requirement is required when unused data items are contained in the data item dictionary. Since an unused data item is not used in a program, a code for definition of the data item is not required. Therefore, a compiler is provided with the function of deleting a code for definition of an unused data item in many cases so that memory sources can be effectively used.
The function of deleting a code for definition of an unused data item is described below by referring to a compiler. In addition to the above mentioned function, an actual compiler has the functions of removing a simple assignment, optimizing a constant calculation, etc. However, for simple explanation, it is assumed that a compiler does not perform optimization other than deletion of a code for definition of an unused data item.
FIG. 1 shows an example of a source program described in COBOL (COmmon Business Oriented Language). In the source program, since the variables IREC01, IDATA11, IDATA12, IDATA13, and IDATA14 defined in lines 130 through 170 are not referred to in the procedure division in and after line 300, they are unused data items. Similarly, the variables WDATA12, WDATA13, WREC02, WDATA21, WDATA22, and WDATA71 defined in lines 210, 220, and 240 through 270 are also unused data items.
When a code for definition of an unused data item is removed by the conventional technology from the source program shown in FIG. 1, the source program shown in FIG. 2 can be obtained. In FIG. 2, the codes in lines 240 through 270 are removed.
FIG. 3 shows an example of a source program described in C. The source program shown in FIG. 3 has almost the same contents as the source program described in COBOL shown in FIG. 1. FIG. 4 shows a result of removing a record for definition of an unused data item from the source program shown in FIG. 3 by the conventional technology.
According to the compiler disclosed in the Japanese Patent Application Laid-open No. Hei 7-239788, it is determined whether or not a variable for which a data type is declared in the program has been used in the process description. If no use is determined, an error message is output to an output device, thereby notifying the user of the wasteful type declarlation in the program, and suppressing the generation of a variable for which a wasteful type declarlation is made. The compiler prevents a wasteful type declarlation from being included in a compiled program.
However, according to the above-mentioned conventional technology, the following unused data item cannot be removed to prevent the address from being shifted in the memory allotted to each data item.
data item forming at least a part of a record (a record is a data item having a hierarchical structure.)
Using the source program described in COBOL shown in FIGS. 1 and 2, the above-mentioned problems are practically described below. IREC01, IDATA11, IDATA12, IDATA13, IDATA14, WDATA12, and WDATA13 defined in the source program shown in FIG. 1 in lines 130 through 170, 210, and 220 are unused data items, but these unused data items are not removed in the source program shown in FIG. 2. Relating to the unused data item IREC01, IFILE01 is used in the SELECT statement in line 70. The unused data items IDATA11, IDATA12, IDATA13, and IDATA14 are data items configuring the IREC01. The unused data items WDATA12 and WDATA13 are data items configuring the record WREC01.
From the source program described in C shown in FIGS. 3 and 4, similar unused data items cannot be removed not only in COBOL but also in other languages.
However, the size of the memory area in a computer is limited. If unused data items in a source program which cannot be deleted are processed as is, then the process may not continue because the available memory area possibly becomes insufficient during compilation, generation of a data item dictionary, etc.
To reduce the memory requirement when a source program is compiled and a data item dictionary is generated for the source program, it is desired that the smallest possible number of unused data items are contained in the source program.